function createXHR() {

    try { return new XMLHttpRequest(); } catch (e) {}
    try { return new ActiveXObject("Msxml2.XMLHTTP.6.0"); } catch (e) {}
    try { return new ActiveXObject("Msxml2.XMLHTTP.3.0"); } catch (e) {}
    try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) {}
    try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {}
    
    alert("XMLHttpRequest not supported!");
    return null;
}

function sendRequest() {

    var xhr = createXHR();

    if (xhr) {
        xhr.open("GET", "http://localhost/", true);
        xhr.onreadystatechange = function() {
            handleResponse(xhr);
        }
        xhr.send();
    }
}

function handleResponse(xhr) {

    if (xhr.readyState == 4 && xhr.status == 200) {
        var parsedResponse = xhr.responseXML;
        var msg = parsedResponse.getElementsByTagName("message")[0].firstChild.nodeValue;
        var out = document.getElementById("responseOutput");
        out.innerHTML = msg;
    }
}

window.onload = function() {

    var btn = document.getElementById("helloButton");

    btn.addEventListener("click", function() {
        sendRequest();
    });

}